package org.xp.judgeplatform.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * 业务异常类
 * 用于处理业务逻辑相关的异常情况
 */
@Getter
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException {

    private final Integer code;
    private final String message;
    private final Integer status;

    /**
     * 创建业务异常
     * @param code 错误代码
     * @param message 错误信息
     */
    public BusinessException(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.status = code; // 默认使用代码作为HTTP状态码
    }
    
    /**
     * 创建业务异常（带HTTP状态码）
     * @param code 错误代码
     * @param message 错误信息
     * @param status HTTP状态码
     */
    public BusinessException(Integer code, String message, Integer status) {
        this.code = code;
        this.message = message;
        this.status = status;
    }
    
    /**
     * 快速创建400错误
     */
    public static BusinessException badRequest(String message) {
        return new BusinessException(400, message, 400);
    }
    
    /**
     * 快速创建401错误
     */
    public static BusinessException unauthorized(String message) {
        return new BusinessException(401, message, 401);
    }
    
    /**
     * 快速创建403错误
     */
    public static BusinessException forbidden(String message) {
        return new BusinessException(403, message, 403);
    }
    
    /**
     * 快速创建404错误
     */
    public static BusinessException notFound(String message) {
        return new BusinessException(404, message, 404);
    }
    
    /**
     * 快速创建500错误
     */
    public static BusinessException serverError(String message) {
        return new BusinessException(500, message, 500);
    }
}
